package com.gxy.learn.design.model.behaviour.iterator;

import java.util.List;

/**
 * @description: 抽象迭代器实现
 * @author: gaoxueyong
 * @Date: 2022/11/8 21:40
 */
public class StudentIteratorImpl implements StudentIterator {
    private List<Student> students;
    private int position = 0;

    public StudentIteratorImpl(List<Student> students) {
        this.students = students;
    }

    /**
     * 判断是否有下一个对象
     *
     * @return boolean
     * @Author gaoxueyong
     * @Date 9:32 下午 2022/11/8
     * @Param []
     **/
    @Override
    public boolean hasNext() {
        return position < students.size();
    }

    /**
     * 获取下一个对象
     *
     * @return com.gxy.learn.design.model.behaviour.iterator.Student
     * @Author gaoxueyong
     * @Date 9:32 下午 2022/11/8
     * @Param []
     **/
    @Override
    public Student next() {
        Student student = students.get(position);
        position++;
        return student;
    }
}
